package com.platform.comm.enums;

import com.platform.comm.constants.EnumOption;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Description: 删除枚举
 *
 * @author libin Created on 2019/7/16
 **/
@EnumOption
public enum YnEnum implements IEnumOption<String> {
    /**
     * 否
     */
    N("0", "否"),

    /**
     * 是
     */
    Y("1", "是");

    @Getter
    private final String code;
    @Getter
    private final String text;

    YnEnum(String code, String text) {
        this.code = code;
        this.text = text;
    }

    /**
     * 枚举项 “键”
     *
     * @return key
     */
    @Override
    public String key() {
        return this.code;
    }

    /**
     * 枚举项 “值”
     *
     * @return value
     */
    @Override
    public String value() {
        return this.text;
    }

    /**
     * 枚举options
     *
     * @return
     */
    @Override
    public Map<String, String> enums() {
        return Arrays.stream(values()).collect(Collectors.toMap(IEnumOption::key, IEnumOption::value));
    }

    public static YnEnum parse(String code) {
        if(YnEnum.N.name().equals(code)){
            return YnEnum.N;
        }
        return YnEnum.Y;
    }

    public static YnEnum parseByCode(String code) {
        if(YnEnum.N.getCode().equals(code)){
            return YnEnum.N;
        }
        return YnEnum.Y;
    }
}
